package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.constant.MessageConstant;
import com.atguigu.entity.PageResult;
import com.atguigu.entity.QueryPageBean;
import com.atguigu.entity.Result;
import com.atguigu.pojo.Address;
import com.atguigu.service.AddressService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/address")
public class AddressContraller {
    @Reference
    AddressService addressService;
    @RequestMapping("/findAllMaps.do")
    public List<Address> findAllMaps(){
        List<Address> addressList = addressService.findAll(); //经纬度和名字
        return addressList;
    }

    @RequestMapping("/addAddress.do")
    public  Result addAddress(@RequestBody Address address){
        addressService.addAddress(address);
        return new Result(true,"添加地址成功");
    }

    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
      return   addressService.findPage(queryPageBean);
    }


    /*@RequestMapping("/findAllMaps.do")
    public Map findAllMaps(){
       Map map = new HashMap();
        List<Map> gridnMaps = new ArrayList<>(); //经纬度集合
        List<Map> nameMaps = new ArrayList<>(); //地址名字集合
        List<Address> addressList = addressService.findAll(); //经纬度和名字
        for (Address address : addressList) {
            String lng = address.getLng();
            String lat = address.getLat();

            Map gridnMap = new HashMap();
            gridnMap.put("lng",lng);
            gridnMap.put("lat",lat);
            gridnMaps.add(gridnMap);

            Map nameMap = new HashMap();
            nameMap.put("addressName",address.getAddressName());
            nameMaps.add(nameMap);
        }
       map.put("gridnMaps",gridnMaps);
       map.put("nameMaps",nameMaps);
       return map;
    }*/
}
